﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Hangjing.Common;
using Hangjing.SQLServerDAL;
using Hangjing.Model;

/// <summary>
/// 商家回收站
/// </summary>
public partial class Admin_Shop_delShopList : AdminPageBase
{

    private string SqlWhere
    {
        get
        {
            object o = ViewState["SqlWhere"];
            return (o == null) ? "" : Convert.ToString(o);
        }
        set
        {
            ViewState["SqlWhere"] = value;
        }
    }

    Points bll = new Points();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            WebUtility.SetDDLCity(DDLArea);
            SqlWhere = "1=1 and InUse = 'Y' and delflag=1 ";
            SqlWhere = new RightsTool().getShopWhere(SqlWhere);

            BindData();
        }
    }

    /// <summary>
    /// 绑定指定的数据
    /// </summary>
    protected void BindData()
    {
        this.AspNetPager1.RecordCount = bll.GetCount(SqlWhere);
        this.rtpTogolist.DataSource = bll.GetList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, SqlWhere, "InTime", 1);
        this.rtpTogolist.DataBind();

        AlertScript.AjaxRegisterScript("init();", UpdatePanel1);
    }

    /// <summary>
    /// 搜索
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btSearch_Click(object sender, EventArgs e)
    {
        SqlWhere = "1=1 and InUse = 'Y' and delflag=1 ";
        SqlWhere = new RightsTool().getShopWhere(SqlWhere);
        if (this.tb_TogoName.Text.Trim() != "")
        {
            SqlWhere += " AND  Name LIKE '%" + WebUtility.InputText(this.tb_TogoName.Text.Trim()) + "%' ";
        }
        if (this.tb_Tel.Text.Trim() != "")
        {
            SqlWhere += " AND Comm LIKE '%" + WebUtility.InputText(this.tb_Tel.Text.Trim()) + "%' ";
        }
        if (this.tb_Address.Text.Trim() != "")
        {
            SqlWhere += " AND Address LIKE '%" + WebUtility.InputText(this.tb_Address.Text.Trim()) + "%' ";
        }
        if (this.tb_Start.Text != "")
        {
            SqlWhere += " AND InTime >= '" + this.tb_Start.Text + "' ";
        }
        if (this.tb_End.Text != "")
        {
            SqlWhere += " AND InTime <= '" + this.tb_End.Text + "' ";
        }
        if (DDLArea.SelectedValue != "-1")
        {
            SqlWhere += " and cityid = " + DDLArea.SelectedValue + "";
        }
        if (this.ddlstar.SelectedValue != "-1")
        {
            SqlWhere += " AND Star = " + this.ddlstar.SelectedValue + " ";
        }
        BindData();
    }

    protected void rtpTogolist_ItemCommand(object sender, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "recover")
        {
            if (bll.DelOrRecoverShop(e.CommandArgument.ToString(),UserHelp.GetAdmin().AdminName,0) > 0)
            {
                AlertScript.RegScript(this.Page, this.UpdatePanel1, "tipsWindown('提示信息','text:操作成功!','250','150','true','2000','true','text');init();");
                BindData();
            }
            else
            {
                AlertScript.RegScript(this.Page, this.UpdatePanel1, "tipsWindown('提示信息','text:操作失败!','250','150','true','2000','true','text');init();");

            }
        }
        if (e.CommandName == "del")
        {
            if (bll.CompletelyDelList(e.CommandArgument.ToString()) > 0)
            {
                Hangjing.AppLog.OperationLog.Info(UserHelp.GetAdmin().AdminName + "删除了商家：" + e.CommandArgument);

                AlertScript.RegScript(this.Page, this.UpdatePanel1, "tipsWindown('提示信息','text:操作成功!','250','150','true','2000','true','text');init();");
                BindData();
            }
            else
            {
                AlertScript.RegScript(this.Page, this.UpdatePanel1, "tipsWindown('提示信息','text:操作失败!','250','150','true','2000','true','text');init();");

            }
        }
    }

    /// <summary>
    /// 批量删除
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void DelList_Click(object sender, EventArgs e)
    {
        string IdList = this.hdDels.Value;
        if (bll.DelOrRecoverShop(IdList,UserHelp.GetAdmin().AdminName,0) > 0)
        {
            AlertScript.RegScript(this.Page, this.UpdatePanel1, "tipsWindown('提示信息','text:操作成功!','250','150','true','1000','true','text');init();");
            BindData();
        }
        else
        {
            AlertScript.RegScript(this.Page, this.UpdatePanel1, "tipsWindown('提示信息','text:操作失败!','250','150','true','1000','true','text');init();");
        }
    }


    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        BindData();
    }
}
